package com.wjjun.base.binding.adapter

import android.widget.TextView
import androidx.databinding.BindingAdapter

/**
 *
 * author : wangjunjun
 * date   : 2022/6/2
 * desc   :
 */

class TextViewAdapter {
    companion object{

        @JvmStatic
        @BindingAdapter(value = ["format", "arg1", "arg2", "arg3"], requireAll = false)
        fun formatString(textView: TextView, format: String?, arg1: Any?, arg2: Any?, arg3: Any?) {
            if (format != null && !format.isEmpty()) {
                if (arg1 != null && arg2 != null && arg3 != null) {
                    textView.text = String.format(format, arg1, arg2, arg3)
                } else if (arg1 != null && arg2 != null) {
                    textView.text = String.format(format, arg1, arg2)
                } else if (arg1 != null) {
                    textView.text = String.format(format, arg1)
                } else {
                    textView.text = ""
                }
            }
        }
    }
}